package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.SysUserDTO;
import com.nineclock.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/query")
    public Result<SysUserDTO> queryUser(@RequestParam String username){
        SysUserDTO sysUserDTO = sysUserService.queryUser(username);
        return Result.success(sysUserDTO);
    }

    @GetMapping("hello")
    @PreAuthorize("hasRole('ADMIN')")
    public Result hello(){
        return Result.success("访问hello");
    }

    @GetMapping("say")
    @PreAuthorize("hasRole('SELLER')")
    public Result say(){
        return Result.success("访问say");
    }
}
